package com.quyeying.controller;

import com.quyeying.utils.result.R;
import com.quyeying.utils.result.ResultEnum;
import org.springframework.web.bind.annotation.*;
import com.quyeying.service.TblPraiseService;
import com.quyeying.entity.TblPraiseEntity;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;

/**
* <p>
* tbl_praise 前端控制器
* </p>
* @author jll
* @since 2022-10-25
*/
@Slf4j
@RestController
@RequestMapping("praiseEntity")
public class TblPraiseController {

    @Resource
    private TblPraiseService tblPraiseService;

    /**
    * 新增
    **/
    @PostMapping("/add")
    public R add(@RequestBody Map<String, Long> map, HttpServletRequest request){
        try {
            return tblPraiseService.add(map, request);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }

    /**
    * 删除
    **/
    @DeleteMapping("/del")
    public R delete(Long id){
        try {
            return tblPraiseService.delete(id);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }

    /**
    * 更新
    **/
    @PostMapping("/update")
    public R update(@RequestBody TblPraiseEntity tblPraiseEntity){
        try {
            return tblPraiseService.updateData(tblPraiseEntity);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }

    /**
    * 分页查询
    **/
    @GetMapping("/findListByPage")
    public R findListByPage(@RequestParam Integer current,
    @RequestParam Integer size){
        try {
            return tblPraiseService.findListByPage(current, size);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }

    /**
    * id查询
    **/
    @GetMapping("/findById")
    public R findById(Long id){
        try {
            return tblPraiseService.findById(id);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }
}
